package com.blacktea.behavioralpatterns.commandpattern;

/**
 * @description: 添加命令类
 * @author: black tea
 * @date: 2023/3/24 20:18
 */
public class AddCommand implements Command {

    /**
     * 内容
     */
    private String text;

    /**
     * 开始的位置
     */
    private int start;

    /**
     * 文本编辑器
     */
    private Editor editor;


    public AddCommand(Editor editor, String text, int start) {
        this.text = text;
        this.start = start;
        this.editor = editor;
    }

    @Override
    public void execute() {
        editor.add(text, start);
    }

    @Override
    public void undo() {
        editor.delete(start, start + text.length());
    }
}
